/**
 * 全局变量
 */
var pageNoOne;//页码
var pageSizeOne;//页码大小
var countOne;//总数
var productInfoName = "";//产品名称
var productInfoCode = "";//产品代码
var productType = "";//产品类别


/**
 * 弹出产品信息选择框
 */
function ejectProInfo(){
	$.jBox($("#divProInfo").html(), {
		id: 'jBoxProInfo', 
		title : "选择产品",
		width : 'auto',
		height : 'auto',
		buttons : {"选择" : false , "关闭" : true },
		submit : function(v, h, f) {
			if (v == false) {
				if(h.find("input[name='radio']:checked").val() != null){
					$("#productId").attr("value",h.find("input[name='radio']:checked").val());
					$("#productName").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[1].innerHTML);
    				$("#productCode").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[3].innerHTML);
    				$("#specifications").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[4].innerHTML);
    				$("#brand").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[5].innerHTML);
    				$("#packaging").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[6].innerHTML);
    				$("#unit").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[7].innerHTML);
    				$("#productCodeNum").attr("value",h.find("input[name='radio']:checked").parent().parent().children("td")[9].innerHTML);
    				$.jBox.close(jBoxProInfo);
    				addPro(); 
    				return true;
				}else{
					$.jBox.tip("请选择产品", "warn");
					return false;
				}
			}
		}
	}); 
}

/**
 * 双击选择产品信息
 */
$("#productName").live('dblclick',function(){
	var newRows = '';
	$.getJSON("/jeesite/a/pro/realDetail/productInfoList",function(data){
		$("#rowProInfo").html(" ");
		if (typeof(data.list) != "undefined" && data.list.length >= 1){
			$.each(data.list, function(i,info){
				 newRows += '<tr><td style="width: 8px;"><input type="radio"class="subBox" name="radio" value="'+info.id+'"/></td>';
				 if(typeof(info.name) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.name+'</td>';
				 }	
				 if(typeof(info.productTypeName) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.productTypeName+'</td>';
				 }	 
				 if(typeof(info.productCode) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.productCode+'</td>';
				 }	 
				 
				 if(typeof(info.specifications) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.specifications+'</td>';
				 }	 
				 if(typeof(info.brand) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.brand+'</td>';
				 }	 
				 
				 if(typeof(info.packaging) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.packaging+'</td>';
				 }	 
				 if(typeof(info.unitName) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.unitName+'</td>';
				 }	 
				 if(typeof(info.remarks) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.remarks+'</td>';
				 }	
				 if(typeof(info.codeNum) == "undefined"){
					 newRows += '<td style="display:none"></td></tr>';
				 }else{
					 newRows += '<td style="display:none">'+info.codeNum+'</td></tr>';
				 }	
			});
		}
		$("#rowProInfo").append(newRows);
		pageNoOne = data.pageNo;
		pageSizeOne = data.pageSize;
		countOne = data.count;
		$("#pageNoOne").html(pageNoOne);
		$("#pageSizeOne").html(pageSizeOne);
		$("#countOne").html(countOne);
		ejectProInfo();
	});
});

//产品列表下一页
$("#nextPageTwo").live("click",function(){
	if(pageNoOne < countOne/pageSizeOne){
		$("#rowProInfo").html("");
		var newRows = '';
		$.getJSON("/jeesite/a/pro/realDetail/productInfoList","pageNo="+(pageNoOne+1)+
		"&name="+productInfoName+"&productCode="+productInfoCode+
		"&productTypeName="+productType,function(data){
			if (typeof(data.list) != "undefined" && data.list.length >= 1){	
				$.each(data.list, function(i,info){
					newRows += '<tr><td style="width: 8px;"><input type="radio"class="subBox" name="radio" value="'+info.id+'"/></td>';
					 if(typeof(info.name) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.name+'</td>';
					 }	
					 if(typeof(info.productTypeName) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.productTypeName+'</td>';
					 }	 
					 if(typeof(info.productCode) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.productCode+'</td>';
					 }	 
					 
					 if(typeof(info.specifications) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.specifications+'</td>';
					 }	 
					 if(typeof(info.brand) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.brand+'</td>';
					 }	 
					 
					 if(typeof(info.packaging) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.packaging+'</td>';
					 }	 
					 if(typeof(info.unitName) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.unitName+'</td>';
					 }	 
					 if(typeof(info.remarks) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.remarks+'</td>';
					 }	
					 if(typeof(info.codeNum) == "undefined"){
						 newRows += '<td style="display:none"></td></tr>';
					 }else{
						 newRows += '<td style="display:none">'+info.codeNum+'</td></tr>';
					 }	
				});
			}
			$("#rowProInfo").append(newRows);
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
			$("#pageNoOne").html(pageNoOne);
			$("#pageSizeOne").html(pageSizeOne);
			$("#countOne").html(countOne);
			ejectProInfo();
			$("#previousPageLiTwo").attr("class","");
			if(pageNoOne >= countOne/pageSizeOne){
				$("#nextPageLiTwo").attr("class","disabled");
			}
			$.jBox.close(jBoxProInfo);
			addPro();
			ejectProInfo();
		});
	}
});

//产品列表上一页
$("#previousPageTwo").live("click",function(){
	if(pageNoOne > 1){
		$("#rowProInfo").html("");
		var newRows = '';
		$.getJSON("/jeesite/a/pro/realDetail/productInfoList","pageNo="+(pageNoOne-1)+
		"&name="+productInfoName+"&productCode="+productInfoCode+
		"&productTypeName="+productType,function(data){
			if (typeof(data.list) != "undefined" && data.list.length >= 1){	
				$.each(data.list, function(i,info){
					newRows += '<tr><td style="width: 8px;"><input type="radio"class="subBox" name="radio" value="'+info.id+'"/></td>';
					 if(typeof(info.name) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.name+'</td>';
					 }	
					 if(typeof(info.productTypeName) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.productTypeName+'</td>';
					 }	 
					 if(typeof(info.productCode) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.productCode+'</td>';
					 }	 
					 
					 if(typeof(info.specifications) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.specifications+'</td>';
					 }	 
					 if(typeof(info.brand) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.brand+'</td>';
					 }	 
					 
					 if(typeof(info.packaging) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.packaging+'</td>';
					 }	 
					 if(typeof(info.unitName) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.unitName+'</td>';
					 }	 
					 if(typeof(info.remarks) == "undefined"){
						 newRows += '<td></td>';
					 }else{
						 newRows += '<td>'+info.remarks+'</td>';
					 }
					 if(typeof(info.codeNum) == "undefined"){
						 newRows += '<td style="display:none"></td></tr>';
					 }else{
						 newRows += '<td style="display:none">'+info.codeNum+'</td></tr>';
					 }	
				});
			}
			$("#rowProInfo").append(newRows);
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
			$("#pageNoOne").html(pageNoOne);
			$("#pageSizeOne").html(pageSizeOne);
			$("#countOne").html(countOne);
			ejectProInfo();
			$("#nextPageLiTwo").attr("class","");
			if(pageNoOne <= 1){
				$("#previousPageLiTwo").attr("class","disabled");
			}
			$.jBox.close(jBoxProInfo);
			addPro();
			ejectProInfo();
		});
	}
});
//按产品名称查询产品
function selectProduct(obj){
	productInfoName = $(obj).prev().prev().prev().prev().prev().val();
	productInfoCode = $(obj).prev().prev().prev().val();
	productType = $(obj).prev().val();
	$("#rowProInfo").html("");
	var newRows = '';
	$.getJSON("/jeesite/a/pro/realDetail/productInfoList","name="+productInfoName+
	"&productCode="+productInfoCode+"&productTypeName="+productType,function(data){
		if (typeof(data.list) != "undefined" && data.list.length >= 1){
			$.each(data.list, function(i,info){
				newRows += '<tr><td style="width: 8px;"><input type="radio"class="subBox" name="radio" value="'+info.id+'"/></td>'
				 if(typeof(info.name) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.name+'</td>';
				 }	
				 if(typeof(info.productTypeName) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.productTypeName+'</td>';
				 }	 
				 if(typeof(info.productCode) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.productCode+'</td>';
				 }	 
				 
				 if(typeof(info.specifications) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.specifications+'</td>';
				 }	 
				 if(typeof(info.brand) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.brand+'</td>';
				 }	 
				 
				 if(typeof(info.packaging) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.packaging+'</td>';
				 }	 
				 if(typeof(info.unitName) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.unitName+'</td>';
				 }	 
				 if(typeof(info.remarks) == "undefined"){
					 newRows += '<td></td>';
				 }else{
					 newRows += '<td>'+info.remarks+'</td>';
				 }
				 if(typeof(info.codeNum) == "undefined"){
					 newRows += '<td style="dispaly:none"></td></tr>';
				 }else{
					 newRows += '<td style="dispaly:none">'+info.codeNum+'</td></tr>';
				 }	
			});
			$("#rowProInfo").append(newRows);
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
		}
		$("#pageNoOne").html(pageNoOne);
		$("#pageSizeOne").html(pageSizeOne);
		$("#countOne").html(countOne);
		if(pageNoOne <= 1){
			$("#previousPageLiTwo").attr("class","disabled");
		}
		if(pageNoOne >= countOne/pageSizeOne){
			$("#nextPageLiTwo").attr("class","disabled");
		}
		$.jBox.close(jBoxProInfo);
		addPro();
		ejectProInfo();
	});
}

